Saving Styled Text
Saving Styled Text
It's easy to read and write styled TextEdit records, even though TextEdit
doesn't include functions to do this for you. Just create a text file with your
plain text in the data fork and your style information in the resource fork.
To write out a TextEdit record:
Create a file of type 'TEXT', and save the text in the data fork.
Select the text you want to save. You have two choices. You can call
TESetSelect. However, the user will see text being selected and may
be confused. Or you can set the selStart and selEnd fields of the
TextEdit Record yourself. Remember to save the old values of selStart
and selEnd so you can restore them when you're done.
Call GetStylScrap to construct the StScrpRec record.
Save the StScrpRec. For example, you could store it in a resource of
type 'styl' in your text file.
To read in a TextEdit record:
Open your text file.
Read the text back into a buffer, and read your style information back
into a StScrpRec record.
Call TEStylInsert, passing it a TextEdit record, a pointer to your
text buffer, and a handle to the StScrpRec.